#include "contactlisttoolitem.h"
#include <QBrush>
#include <QPainter>
#include <QPixmap>
#include <QRect>
#include "ui_contactlisttoolitem.h"
ContactListToolItem::ContactListToolItem(QWidget *parent, QString icon, QString text)
    : QWidget(parent)
    , ui(new Ui::ContactListToolItem)
    , _showRedPoint(false)
{
    ui->setupUi(this);
    setObjectName("toolItem");
    if (!icon.isEmpty()) {
        QPixmap p(icon);
        p = p.scaled(ui->tool_iocn->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
        ui->tool_iocn->setPixmap(p);
    }
    if (!text.isEmpty()) {
        ui->tool_lb->setText(text);
    }
}

ContactListToolItem::~ContactListToolItem()
{
    delete ui;
}

void ContactListToolItem::slot_RedPointVisible(bool visible)
{
    _showRedPoint = visible;
    update();
}

void ContactListToolItem::paintEvent(QPaintEvent *event)
{
    QWidget::paintEvent(event);
    if (_showRedPoint) {
        QPainter p(this);
        p.setBrush(Qt::red);
        p.setPen(Qt::NoPen);
        QRect rect(200, 2, 10, 10);
        p.drawRoundedRect(rect, 5, 5);
    }
}


void ContactListToolItem::mousePressEvent(QMouseEvent *event)
{
    emit sig_clicked();
    QWidget::mousePressEvent(event);
}
